package com.sharker.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;

import com.sharker.R;
import com.sharker.adapter.TopicLAdapter;
import com.sharker.models.data.TopicData;
import com.sharker.network.SharkerParams;
import com.sharker.view.Toptitlebar;
import com.sharker.wiget.DividerItemDecoration;

import org.xutils.common.Callback;
import org.xutils.x;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TopicallActivity extends AppCompatActivity {

    @BindView(R.id.topic_all_titlebar)
    Toptitlebar topicAllTitlebar;
    @BindView(R.id.topic_all_recycler)
    RecyclerView topicAllRecycler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_topicall);
        getSupportActionBar().hide();
        ButterKnife.bind(this);
        listTopic("list_topic","",0,0);
        topicAllTitlebar.setleftOnclick(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    public void listTopic(String uri, String category, int page_index, int sort_by) {

        SharkerParams params = new SharkerParams(uri);

        if (!TextUtils.isEmpty(category)) {
            params.addBodyParameter("category", category);
        }

        params.addBodyParameter("page_size", "25");

        params.addBodyParameter("page_index", "" + page_index);

        if (sort_by != 0) {
            params.addBodyParameter("sort_by", "" + sort_by);
        }

        x.http().post(params, new Callback.CommonCallback<TopicData>() {
            @Override
            public void onSuccess(TopicData result) {
                topicAllRecycler.setLayoutManager(new LinearLayoutManager(TopicallActivity.this));
                topicAllRecycler.addItemDecoration(new DividerItemDecoration(TopicallActivity.this, DividerItemDecoration.VERTICAL_LIST));
                TopicLAdapter topicLAdapter = new TopicLAdapter(TopicallActivity.this, result.getTopic());
                topicAllRecycler.setAdapter(topicLAdapter);
               /* topicAdapter.setTopicOnitemListener(new TopicAdapter.TopicOnitemListener() {
                    @Override
                    public void OnItemclick(View view, int position) {
                        Intent intent=new On
                    }
                });*/

            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }
}
